package com.example.server.util;

import com.example.javaapitest.testcase.TxTest;
import org.testng.ITestNGListener;
import org.testng.TestNG;

import java.io.*;
import java.util.*;

public class RunTestngXml {
	public static void runClass() throws ClassNotFoundException, IOException {
		TestNG testNG = new TestNG();
//		Class[] classes = {TxTest.class, Class.forName("com.example.javaapitest.testcase.TestFmc")};
//		testNG.setTestClasses(classes);
		Class[] listenclasses = {Class.forName("com.example.javaapitest.listener.TestLogListener")};
		testNG.setListenerClasses(Arrays.asList(listenclasses));

//		File file = new File("");
//		String rootPath = "";
//		//获取项目的根路径
//		rootPath = file.getCanonicalPath();
//		//获取根路径加相对路径的文件夹
//		File propertiesFile = new File(rootPath+"/src/main/resources/testProperties");
		testNG.setXmlPathInJar("classpath:testngXml/testSuite.xml");
		testNG.run();
	}


	public static void runXml() throws IOException {
		TestNG testNG = new TestNG();
		List<String> suites = new ArrayList<String>();
		//suites.add("D:\\a\\tx-shop-server\\user-server\\src\\main\\resources\\testngXml\\testSuite.xml");//此处为xml的绝对路径
		File file = new File("");
		String rootPath = "";
		//获取项目的根路径
		rootPath = file.getCanonicalPath();
		suites.add(rootPath + "/user-server/src/main/resources/testngXml/testSuite.xml");
		testNG.setTestSuites(suites);
		testNG.run();
	}

	public static void main(String[] args) throws ClassNotFoundException, IOException {
		runXml();
	}
}
